

//
//  KMenuRootViewController.m
//  DrugPin
//
//  Created by guohe on 2018/9/8.
//  Copyright © 2018年 outang. All rights reserved.
//
#import "KHomePageViewController.h"
#import "KDiscoveryRootViewController.h"
#import "KProceedsRootViewController.h"
#import "KMineRootViewController.h"
#import "KMenuRootViewController.h"

#define KNormalText KColorOneAlpha(51, 51, 51)
#define KSelectedText KColorOneAlpha(48, 138, 245)

@interface KMenuRootViewController ()<UITabBarDelegate>
@end

@implementation KMenuRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置TabBar图片下面字体的颜色
    [self TabBarTitleColor];
    //设置所有控制器的跳转
    [self setTabBarAllControl];
    
}

#pragma mark - 设置TabBar图片下面字体的颜色
-(void)TabBarTitleColor
{
    //未选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:KNormalText,NSFontAttributeName:[UIFont systemFontOfSize:10.f]} forState:UIControlStateNormal];
    
    //选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:KSelectedText,NSFontAttributeName:[UIFont systemFontOfSize:10.f]} forState:UIControlStateSelected];
}

#pragma mark - 创建TabBar
-(void)setTabBarAllControl
{
    self.homePageVC = [[KHomePageViewController alloc] init];

    [self setUpOneChildViewControl:self.homePageVC image:[UIImage imageNamed:@"icon_tab_1_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_1_highlight"] title:@"首页"];

    self.discoveryVC = [[KDiscoveryRootViewController alloc] init];
    
    [self setUpOneChildViewControl:self.discoveryVC image:[UIImage imageNamed:@"icon_tab_2_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_2_highlight"] title:@"发现"];

    self.proceedsVC = [[BaseWebViewController alloc] init];
    
    self.proceedsVC.urlStr = [NSString stringWithFormat:@"%@user/income?_code=%@",ServerAddressURLAPI,[KUserLoginModel shareInstance].Code ? [KUserLoginModel shareInstance].Code : [KWXLoginUserListModel shareInstance].Code];

    [self setUpOneChildViewControl:self.proceedsVC image:[UIImage imageNamed:@"icon_tab_3_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_3_highlight"] title:@"收益"];

    self.mineVC = [[BaseWebViewController alloc] init];
//    self.mineVC = [[KMineRootViewController alloc] init];

    self.mineVC.urlStr = [NSString stringWithFormat:@"%@user/index?_code=%@",ServerAddressURLAPI,[KUserLoginModel shareInstance].Code ? [KUserLoginModel shareInstance].Code : [KWXLoginUserListModel shareInstance].Code];
    //显示导航栏右边两个按钮
    [self.mineVC showCustomNavigationRightButtonWithimage:[UIImage imageNamed:@"icon_erweima"] hightlightImage:[UIImage imageNamed:@"icon_erweima"] image2:[UIImage imageNamed:@"icon_set"]  hightlightImage2:[UIImage imageNamed:@"icon_set"]];

    [self setUpOneChildViewControl:self.mineVC image:[UIImage imageNamed:@"icon_tab_4_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_4_highlight"] title:@"我的"];
}

#pragma mark - TableBar抽取方法，使得前面的代码更简洁
-(void)setUpOneChildViewControl:(UIViewController *)vc image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title
{
    vc.title = title;
    vc.tabBarItem.image         = image;
    vc.tabBarItem.selectedImage = selectedImage;
    
    //设置导航条
    KNavigationViewController * nav = [[KNavigationViewController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    KTabBar * tabbar = [[KTabBar alloc] init];
//    tabbar.wj_delegate = self;
        tabbar.delegate = self;
    [self setValue:tabbar forKey:@"tabBar"];
}

//-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
//    NSLog(@"%@",item.title);
//
//    if ([item.title isEqualToString:@"首页"]) {
//        [self homePageLoadData];
//    }
//    if ([item.title isEqualToString:@"发现"]) {
//        [self discoveryLoadData];
//    }
//    if ([item.title isEqualToString:@"收益"]) {
//        [self proceedsLoadData];
//    }
//    if ([item.title isEqualToString:@"我的"]) {
//        [self mineLoadData];
//    }
//}
//
//
//-(void)homePageLoadData{
//    self.homePageVC = [[KHomePageViewController alloc] init];
//    [self setUpOneChildViewControl:self.homePageVC image:[UIImage imageNamed:@"icon_tab_1_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_1_highlight"] title:@"首页"];
//}
//
//-(void)discoveryLoadData{
//    self.discoveryVC = [[KDiscoveryRootViewController alloc] init];
//    [self setUpOneChildViewControl:self.discoveryVC image:[UIImage imageNamed:@"icon_tab_2_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_2_highlight"] title:@"发现"];
//}
//
//-(void)proceedsLoadData{
////    self.proceedsVC = [[KProceedsRootViewController alloc] init];
//    self.proceedsVC = [[BaseWebViewController alloc] init];
//
//    [self setUpOneChildViewControl:self.proceedsVC image:[UIImage imageNamed:@"icon_tab_3_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_3_highlight"] title:@"收益"];
//}
//
//-(void)mineLoadData{
//        [self setUpOneChildViewControl:self.mineVC  image:[UIImage imageNamed:@"icon_tab_4_nor"] selectedImage:[UIImage imageNamed:@"icon_tab_4_highlight"] title:@"我的"];
//        self.mineVC.urlStr = [NSString stringWithFormat:@"%@user/index?_code=%@",ServerAddressURLAPI,[KUserLoginModel shareInstance].Code ? [KUserLoginModel shareInstance].Code : [KWXLoginUserListModel shareInstance].Code];
//}




@end
